package com.hnkywl.sts.dao.kcgl;

import com.hnkywl.sts.dao.base.RegionDao;
import com.hnkywl.sts.dao.organ.GsjgDao;
import com.hnkywl.sts.dao.sys.YgDao;
import com.hnkywl.sts.entity.organ.Ck;
import com.hnkywl.sts.entity.organ.Gsjg;
import com.hnkywl.sts.entity.organ.Nbgs;
import com.hnkywl.sts.entity.sys.Yg;
import com.hnkywl.sts.entity.xsgl.Gd;
import com.hnkywl.sts.service.sys.YgService;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-4-30
 * Time: 上午11:31
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class KcgdDao extends SimpleHibernateTemplate<Gd, Long> {
    private YgDao ygDao;

    private GsjgDao gsjgDao;

    public Page<Gd> findList(String gdwyh, String clh, String bh, String cpm, String pm, String cz, String ggxh, String zyzt, String kcgdstart, String kcgdend, int pageNo, int pageSize) {
        String hql;
        List<Object> param = new ArrayList<Object>();
        StringBuilder condition = new StringBuilder();
        Page<Gd> page = new Page<Gd>(pageNo, pageSize, 0);
        //==============条件拼接===============
        if (StringUtils.isNotBlank(gdwyh)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" resource_serial_number like ? ");
            param.add("%" + gdwyh.trim() + "%");
        }

        if (StringUtils.isNotBlank(clh)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" matNo like ? ");
            param.add("%" + clh.trim() + "%");
        }

        if (StringUtils.isNotBlank(bh)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" packageId like ? ");
            param.add("%" + bh.trim() + "%");
        }

        if (StringUtils.isNotBlank(cpm)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" pc like ? ");
            param.add("%" + cpm.trim() + "%");
        }

        if (StringUtils.isNotBlank(pm)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" prodDesc like ? ");
            param.add("%" + pm.trim() + "%");
        }

        if (StringUtils.isNotBlank(cz)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" material like ? ");
            param.add("%" + cz.trim() + "%");
        }

        if (StringUtils.isNotBlank(ggxh)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" spec like ? ");
            param.add("%" + ggxh.trim() + "%");
        }

        if (StringUtils.isNotBlank(zyzt)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" zyzt = ? ");
            param.add(zyzt.trim());
        }

        if (StringUtils.isNotBlank(kcgdstart)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" to_char(dateCreated , 'yyyy-MM-dd') >= ? ");
            param.add(kcgdstart.trim());
        }

        if (StringUtils.isNotBlank(kcgdend)) {
            if (condition.length() != 0)
                condition.append(" and ");
            condition.append(" to_char(dateCreated , 'yyyy-MM-dd') =< ? ");
            param.add(kcgdend.trim());
        }

        //==============记录数量===============
        hql = "select count(*) from Gd where 1=1 ";
        if (condition.length() != 0)
            hql = hql + " and " + condition;
        Long c = null;
        if (param.size() != 0) {
            c = (Long) findUnique(hql, param.toArray());
            page.setTotalCount(c.intValue());
        } else {
            c = (Long) findUnique(hql);
            page.setTotalCount(c.intValue());
        }
        if (c == 0)
            return page;
        //==============查询结果===============
        hql = "from Gd where 1=1 order by dateCreated desc";
        if (condition.length() != 0)
            hql = hql + " and " + condition + "";
        if (param.size() != 0)
            return find(page, hql, param.toArray());
        return find(page, hql);
    }

    public List<Map> findSumKh(String gdwyh, String clh, String bh, String cpm, String pm, String cz, String ggxh, String zyzt, String kcgdstart, String kcgdend) {
        Map<String, Object> param = new HashMap<String, Object>();
        List<String> condition = new ArrayList<String>();

        String sql = "select nvl(sum(g.measure),0) as \"zzl\" from t_biz_gd g " +
                "where g.deleted = 0 ";

        if (StringUtils.isNotEmpty(gdwyh)) {
            condition.add(" g.resource_serial_number like :gdwyh ");
            param.put("gdwyh", "%" + gdwyh.trim() + "%");
        }

        if (StringUtils.isNotEmpty(clh)) {
            condition.add(" g.matno like :clh ");
            param.put("clh", "%" + clh.trim() + "%");
        }

        if (StringUtils.isNotEmpty(bh)) {
            condition.add(" g.packageid like :bh ");
            param.put("bh", "%" + bh.trim() + "%");
        }

        if (StringUtils.isNotEmpty(cpm)) {
            condition.add(" g.pc like :cpm ");
            param.put("cpm", "%" + cpm.trim() + "%");
        }

        if (StringUtils.isNotBlank(pm)) {
            condition.add(" g.prodDesc like :pm ");
            param.put("pm", "%" + pm.trim() + "%");
        }

        if (StringUtils.isNotBlank(cz)) {
            condition.add(" g.material like :cz ");
            param.put("cz", "%" + cz.trim() + "%");
        }

        if (StringUtils.isNotBlank(ggxh)) {
            condition.add(" g.spec like :ggxh ");
            param.put("ggxh", "%" + ggxh.trim() + "%");
        }

        if (StringUtils.isNotBlank(zyzt)) {
            condition.add(" g.zyzt = :zyzt ");
            param.put("zyzt",zyzt);
        }

        if (StringUtils.isNotBlank(kcgdstart)) {
            condition.add(" to_char(dateCreated , 'yyyy-MM-dd') >= :kcgdstart ");
            param.put("kcgdstart",kcgdstart);
        }

        if (StringUtils.isNotBlank(kcgdend)) {
            condition.add(" to_char(dateCreated , 'yyyy-MM-dd') =< :kcgdend ");
            param.put("kcgdend",kcgdend);
        }

        String whereSql = "";
        if (!condition.isEmpty())
            whereSql = " and " + StringUtils.join(condition, " and ");

        sql += whereSql;

        SQLQuery sqlQuery = createSQLQuery(sql);
        List<Map> list = sqlQuery
                .setProperties(param)
                .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
                .list();
        return list;
    }

    private String createSqlCkDataRegion(String joinStr, String alias) {
        Yg yg = this.ygDao.get(YgService.getCurrentYg().getId());
        List<Ck> list = yg.getCkList();
        if (list != null && list.size() > 0) {
            String ids = "";
            for (Ck ck : list) {
                ids += ck.getId() + ",";
            }
            ids = ids.substring(0, ids.length() - 1);

            String joinStrName = StringUtils.isEmpty(joinStr) ? "" : joinStr + " and ";
            String aliasName = StringUtils.isEmpty(alias) ? "" : alias + ".";
            String regionSql = "";
            switch (YgService.getCurrentYgCxfw()) {
                case 0:
                    regionSql += " {0} 1=1";
                    break;
                case 1:
                    regionSql += " {0} ({1}ck_id in (" + ids + "))";
                    break;
                case 2:
                    regionSql += " {0} ({1}ck_id in (" + ids + "))";
                    break;
                case 3:
                    regionSql += " {0} ({1}ck_id in (" + ids + "))";
                    break;
            }
            return regionSql.replace("{0}", joinStrName).replace("{1}", aliasName);
        } else {
            List<Gsjg> gslist = yg.getSsjgList();
            String ids = "";
            for (Gsjg gsjg : gslist) {
                ids += gsjg.getId() + ",";
            }
            ids = ids.substring(0, ids.length() - 1);

            String joinStrName = StringUtils.isEmpty(joinStr) ? "" : joinStr + " and ";
            String aliasName = StringUtils.isEmpty(alias) ? "" : alias + ".";
            String regionSql = "";
            switch (YgService.getCurrentYgCxfw()) {
                case 0:
                    regionSql += " {0} 1=1";
                    break;
                case 1:
                    regionSql += " {0} {1}createOrgan_id in (select sjjg_id from T_SYS_GSJG gs where gs.id in (" + ids + "))";
                    break;
                case 2:
                    regionSql += " {0} {1}createOrgan_id in (select sjjg_id from T_SYS_GSJG gs where gs.id in (" + ids + "))";
                    break;
                case 3:
                    regionSql += " {0} {1}createDepartment_id =" + YgService.getCurrentYgGsId();
                    regionSql += " {0} {1}createUser_id =" + YgService.getCurrentYg().getId();
                    break;
            }
            return regionSql.replace("{0}", joinStrName).replace("{1}", aliasName);
        }

    }

    private String formatDate(Date date) {
        if (date == null)
            date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String s = sdf.format(date);
        return s;
    }

    /**
     * 查找所有的卡号
     *
     * @return
     */
//    public List<Kh> findKh() {
//        String hql = "from Kh where deleted = 0 " + RegionDao.createDataRegion("and");
//        return find(hql);
//    }
    public List<Map> findKhList(Long sbgsId, String cggsJc, String code, Long ckId, String jtwzname, String khbm, Date endDate, String wzmc, String qk) {
        Map<String, Object> param = new HashMap<String, Object>();
        List<String> condition = new ArrayList<String>();
        String endDateStr = formatDate(endDate);
        String currentDateStr = formatDate(new Date());

        String yggl = StringUtils.EMPTY;
        if (existsSQLQuery("select 1 from t_sys_yg_bmfw where yg_id = ?", YgService.getCurrentYg().getId())) {
            yggl = " inner join v_wzbm_gg_yg_search bmfw  on this_.JTWZ_ID = bmfw.ggid and bmfw.yg_id=" + YgService.getCurrentYg().getId();
            //where = " bmfw.yg_id = " + YgService.getCurrentYg().getId();
        } else if (existsSQLQuery("select 1 from v_wzbm_gg_search  where gsid = ?", YgService.getCurrentYgGsId())) {
            yggl = " inner join v_wzbm_gg_search bmfw on this_.JTWZ_ID = bmfw.ggid and bmfw.gsid=" + YgService.getCurrentYgGsId();
        }

        String sqlColumn = "select t.id as \"id\", t.khbm as \"khbm\", t.qk as \"qk\", t.qkr as \"qkr\",t.jtwz_id as \"jtwz_id\"," +
                " t.jtwz_code as \"jtwz_code\",t.jtwz_oldcode as \"jtwz_oldcode\", t.jtwz_name as \"jtwz_name\",t.jtwz_ggxh as \"jtwz_ggxh\"," +
                " t.cgd_id as \"cgd_id\",t.cgd_cgdh as \"cgd_cgdh\", t.cd_id as \"cd_id\", t.cd_z as \"cd_z\"," +
                "  t.dw_z as \"dw_z\", t.ck_id as \"ck_id\", t.ck_mc as \"ck_mc\"," +
                "  t.sl as \"sl\",t.bz as \"bz\",t.chd as \"chd\",t.js as \"js\",t.jz as \"jz\",t.wsdj as \"wsdj\"," +
                " t.wsje as \"wsje\",t.zlqk as \"zlqk\", t.kkdsl as \"kkdsl\", t.lastUpdated as \"lastUpdated\",t.rkrq as \"rkrq\" ,t.sbgs_jc as \"sbgs_jc\",t.sbgs_id as \"sbgs_id\",t.sbbm_id as \"sbbm_id\",t.sbbm_qc as \"sbbm_qc\",t.cggs_id as \"cggs_id\",t.cggs_jc as \"cggs_jc\",t.createuser_id as \"createuser_id\"";
        String sqlBase = " (select this_.id as id, khbm as khbm,qk as qk,(select createuser5_.xm from T_SYS_YG createuser5_  where this_.CREATEUSER_ID =createuser5_.id) as qkr,jtwz1_.id as jtwz_id,jtwz1_.code as jtwz_code,jtwz1_.oldcode as jtwz_oldcode,jtwz1_.name as jtwz_name,jtwz1_.cz||' '||jtwz1_.ggxh as jtwz_ggxh,cgd4_.id as cgd_id," +
                "cgd4_.cgdh as cgd_cgdh,this_.CD_SJZDZ_ID as cd_id, (select cd2_.z from T_SYS_SJZDZ cd2_ where  this_.CD_SJZDZ_ID = cd2_.id) as cd_z,jtwz1_.dw as dw_z, this_.CK_ID as ck_id,(select ck3_.mc  from T_SYS_CK ck3_ where this_.CK_ID = ck3_.id) as ck_mc," +
                "this_.sl+NVL((select sum(xs.ck_sbsl) from T_BIZ_XSMX xs,T_BIZ_XSD xsd where xs.xsd_id=xsd.id and xs.kh_id=this_.id and xsd.deleted!=1 and xsd.yck=1 and xsd.cksj between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "-NVL((select sum(cg.rksl) from T_BIZ_CGDMX cg where cg.cgd_id=cgd4_.id and cg.kh_id=this_.id and cgd4_.deleted!=1 and cgd4_.yrk=1 and cgd4_.rksj between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "+NVL((select sum(llddmx.flsl) from T_BIZ_LLDMX llddmx,T_BIZ_LLD lld where llddmx.lld_id=lld.id and llddmx.kh_id=this_.id and lld.deleted!=1 and this_.ck_id=lld.ck_id and lld.flrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "+NVL((select sum(zkdmx.zcsl) from T_BIZ_ZKDMX zkdmx,T_BIZ_ZKD zkd where zkdmx.zkd_id=zkd.id and zkdmx.kh_id=this_.id and zkd.deleted!=1 and  zkd.zkrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "-NVL((select sum(zkdmx.zrsl) from T_BIZ_ZKDMX zkdmx,T_BIZ_ZKD zkd where zkdmx.zkd_id=zkd.id and zkdmx.new_kh_id =this_.id and zkd.deleted!=1  and zkd.zkrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0) as sl," +
                "this_.bz as bz,this_.chd as chd,this_.js as js,this_.jz as jz,this_.wsdj as wsdj," +
                "this_.wsdj * (this_.sl+NVL((select sum(xs.ck_sbsl) from T_BIZ_XSMX xs,T_BIZ_XSD xsd where xs.xsd_id=xsd.id and xs.kh_id=this_.id and xsd.deleted!=1 and xsd.yck=1 and xsd.cksj between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "-NVL((select sum(cg.rksl) from T_BIZ_CGDMX cg where cg.cgd_id=cgd4_.id and cg.kh_id=this_.id and cgd4_.deleted!=1 and cgd4_.yrk=1 and cgd4_.rksj between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "+NVL((select sum(llddmx.flsl) from T_BIZ_LLDMX llddmx,T_BIZ_LLD lld where llddmx.lld_id=lld.id and llddmx.kh_id=this_.id and lld.deleted!=1 and this_.ck_id=lld.ck_id and lld.flrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "+NVL((select sum(zkdmx.zcsl) from T_BIZ_ZKDMX zkdmx,T_BIZ_ZKD zkd where zkdmx.zkd_id=zkd.id and zkdmx.kh_id=this_.id and zkd.deleted!=1 and  zkd.zkrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "-NVL((select sum(zkdmx.zrsl) from T_BIZ_ZKDMX zkdmx,T_BIZ_ZKD zkd where zkdmx.zkd_id=zkd.id and zkdmx.new_kh_id =this_.id and zkd.deleted!=1 and  zkd.zkrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)) as wsje," +
                "this_.zlqk as zlqk,cgd4_.gys_id as gys," +
                "this_.kkdsl+NVL((select sum(xs.ck_sbsl) from T_BIZ_XSMX xs,T_BIZ_XSD xsd where xs.xsd_id=xsd.id and xs.kh_id=this_.id and xsd.deleted!=1 and  xsd.cksj between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "-NVL((select sum(cg.rksl) from T_BIZ_CGDMX cg where cg.cgd_id=cgd4_.id and cg.kh_id=this_.id and cgd4_.deleted!=1 and cgd4_.yrk=1  and cgd4_.rksj between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0) " +
                "+NVL((select sum(llddmx.flsl) from T_BIZ_LLDMX llddmx,T_BIZ_LLD lld where llddmx.lld_id=lld.id and llddmx.kh_id=this_.id and lld.deleted!=1 and this_.ck_id=lld.ck_id and lld.flrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "+NVL((select sum(zkdmx.zcsl) from T_BIZ_ZKDMX zkdmx,T_BIZ_ZKD zkd where zkdmx.zkd_id=zkd.id and zkdmx.kh_id=this_.id and zkd.deleted!=1 and  zkd.zkrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0)" +
                "-NVL((select sum(zkdmx.zrsl) from T_BIZ_ZKDMX zkdmx,T_BIZ_ZKD zkd where zkdmx.zkd_id=zkd.id and zkdmx.new_kh_id =this_.id and zkd.deleted!=1 and  zkd.zkrq between to_date('" + endDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss') and to_date('" + currentDateStr + " 23:59:59','yyyy-mm-dd hh24:mi:ss')),0) as kkdsl," +
                "this_.last_updated as lastUpdated,this_.rkrq as rkrq, this_.sbgs_id as sbgs_id,(select g1_.jc from t_SYS_GSJG g1_ where this_.sbgs_id = g1_.id)  as sbgs_jc, this_.sbbm_id as sbbm_id,(select g2_.qc from t_SYS_GSJG g2_ where this_.sbbm_id = g2_.id) as sbbm_qc,this_.cggs_id as cggs_id,(select g3_.jc from t_SYS_GSJG g3_ where this_.cggs_id = g3_.id)  as  cggs_jc,this_.CREATEUSER_ID as createuser_id,this_.CREATEORGAN_ID as CREATEORGAN_ID,this_.Createdepartment_Id as Createdepartment_Id" +
                " from T_BIZ_KH this_" + yggl +
                " left outer join T_BIZ_CGD cgd4_ on this_.CGD_ID = cgd4_.id" +
                " left outer join T_SYS_GG jtwz1_ on this_.JTWZ_ID = jtwz1_.id where this_.deleted = 0 ) t";

        if (StringUtils.isNotEmpty(khbm)) {
            condition.add(" t.khbm like:khbm ");
            param.put("khbm", "%" + khbm + "%");
        }

        if (StringUtils.isNotEmpty(jtwzname)) {
            condition.add(" jtwz1_.cz||' '||jtwz1_.ggxh like:jtwz_ggxh ");
            param.put("jtwz_ggxh", "%" + jtwzname + "%");
        }

        if (StringUtils.isNotEmpty(code)) {
            condition.add(" (t.jtwz_code like :jtwz_code or t.jtwz_oldcode like :jtwz_oldcode) ");
            param.put("jtwz_code", code + "%");
            param.put("jtwz_oldcode", code + "%");
        }

        if (ckId != null) {
            condition.add(" t.ck_id=:ck_id ");
            param.put("ck_id", ckId);
        }

        if (sbgsId != null) {
            Gsjg g = this.gsjgDao.get(sbgsId);
            if (g instanceof Nbgs) {
                condition.add(" t.sbgs_id = :sbgs_id ");
                param.put("sbgs_id", g.getId());
            } else {
                condition.add(" t.sbbm_id = :sbbm_id ");
                param.put("sbbm_id", g.getId());
            }
        }
        if (StringUtils.isNotEmpty(cggsJc)) {
            condition.add(" t.cggs_id = :cggs_id ");
            param.put("cggs_id", cggsJc);
        }

        if (StringUtils.isNotEmpty(qk)) {
            condition.add(" t.qk=:qk ");
            param.put("qk", qk.equals("true"));
        }

        if (StringUtils.isNotEmpty(wzmc)) {
            condition.add(" t.jtwz_name like :wzmc ");
            param.put("wzmc", wzmc);
        }

        condition.add(" t.rkrq<=to_date('" + endDateStr + " 23:59:59','yyyy-MM-dd hh24:mi:ss') ");

        String whereSql = "";
        if (!condition.isEmpty())
            whereSql = " where " + StringUtils.join(condition, " and ");
        String orderSql = " order by t.jtwz_code asc";
        String resultSql = sqlColumn + " from (" + sqlBase + ") " + whereSql + " and " + createSqlCkDataRegion(null, "t") + orderSql;

        List<Map> list = createSQLQuery(resultSql)
                .setProperties(param)
                .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
                .list();
        return list;
    }

    public List<Map> findKcgdGdWzmxFromKhIds(List<Long> khIds) {
//        Criteria criteria = getSession().createCriteria(Kh.class)
//                .createAlias("jtwz", "wzgg", CriteriaSpecification.LEFT_JOIN)
//                .createAlias("ck", "ck", CriteriaSpecification.LEFT_JOIN)
//                .createAlias("cd", "cd", CriteriaSpecification.LEFT_JOIN)
//                .setProjection(Projections.projectionList()
//                                .add(Projections.sqlProjection("this_.id as id", new String[]{"id"}, new Type[]{Hibernate.LONG}))
//                                .add(Property.forName("khbm").as("kh.khbm"))
//                                .add(Property.forName("kkdsl").as("kkdsl"))
//                                .add(Property.forName("wsdj").as("wsdj"))
//                                .add(Property.forName("chd").as("chd"))
//                                .add(Property.forName("jz").as("jz"))
//                                .add(Property.forName("wzgg.id").as("wzgg.id"))
//                                .add(Property.forName("wzgg.code").as("wzgg.code"))
//                                .add(Property.forName("wzgg.name").as("wzgg.name"))
//                                .add(Projections.sqlProjection("wzgg1_.cz||' '||wzgg1_.ggxh as \"wzgg.ggxh\"", new String[]{"wzgg.ggxh"}, new Type[]{Hibernate.STRING}))
//                                .add(Property.forName("wzgg.dw").as("wzgg.dw"))
//                                .add(Property.forName("wzgg.th").as("wzgg.th"))
//                                .add(Property.forName("cd.id").as("cd.id"))
//                                .add(Property.forName("cd.z").as("cd.z"))
//                                .add(Property.forName("sl").as("sl"))
//                                .add(Property.forName("js").as("js"))
//                                .add(Property.forName("khdj").as("khdj"))
//                ).add(Restrictions.in("id", khIds))
//                .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
//        return (List<Map>) criteria.list();
        return null;
    }

    @Autowired
    public void setYgDao(YgDao ygDao) {
        this.ygDao = ygDao;
    }

    @Autowired
    public void setGsjgDao(GsjgDao gsjgDao) {
        this.gsjgDao = gsjgDao;
    }
}
